class Solution {
public:
    vector<int> findAnagrams(string s, string p) 
    {
        int hash1[26] = {0};
        int hash2[26] = {0};
        vector<int> ret;
        int n = p.size();
        for(auto e : p)
        {
            //通过映射来计数
            hash1[e - 'a']++;
        }
        for(int left = 0, right = 0,count = 0;right < s.size();right++)
        {
            char in = s[right];
            //进窗口 + 维护窗口
            if(++hash2[in-'a'] <= hash1[in-'a'])
                count++;
            
            if(right-left+1 > n)//判断
            {
                char out = s[left++];
                if(hash2[out - 'a']-- <= hash1[out - 'a'])
                    count--;
            }
            if(count == n)
                ret.push_back(left);
        }
        return ret;
    }
};
